/**
 * Project Name:fire-industry-DM-center
 * File Name:ConverterManager.java
 * Package Name:com.firestone.converters.center
 * Date:2018年4月13日下午5:46:54
 *
*/

package com.firestone.converters.center;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.baomidou.mybatisplus.plugins.Page;
import com.firestone.bean.dto.manager.ManagerDTO;
import com.firestone.bean.vo.BaseListVO;
import com.firestone.bean.vo.manager.ManagerVO;
import com.firestone.common.tool.DateUtils;
import com.firestone.core.constants.ConstantMapKey;

/**
 * @Description: TODO(管理员控制器模型转换器)
 * @author CAIYJ
 * @date 2018年4月13日 下午5:46:54
 */
public final class ConverterManager {
    /**
     * @Description: TODO(列表返回模型转换)
     * @param page
     * @return
     * @author CAIYJ
     * @date 2018年4月13日 下午3:08:37
     * @lastModifier CAIYJ
     */
    public static final BaseListVO<ManagerVO> convertListVO(
            Page<ManagerDTO> page) {
        BaseListVO<ManagerVO> base = new BaseListVO<ManagerVO>();
        if (page != null) {
            if (page.getRecords() != null && page.getRecords().size() > 0) {
                List<ManagerVO> list = new ArrayList<>();
                for (ManagerDTO dto : page.getRecords()) {
                    ManagerVO vo = new ManagerVO();
                    BeanUtils.copyProperties(dto, vo);
                    if (dto.getCreateTime() != null) {
                        vo.setCreateTime(
                                DateUtils.getTimeStampStr(dto.getCreateTime()));
                    }
                    if (dto.getUpdateTime() != null) {
                        vo.setUpdateTime(
                                DateUtils.getTimeStampStr(dto.getUpdateTime()));
                    }
                    vo.setIsDelete(
                            ConstantMapKey.IS_DELETE.get(dto.getIsDelete()));
                    list.add(vo);
                }
                base.setList(list);
            }
            base.setCount(page.getTotal());
        }
        return base;
    }
}
